package com.ruoyi.archives.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.archives.domain.SysRelatives;
import com.ruoyi.archives.service.ISysRelativesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭成员情况Controller
 * 
 * @author gzhankh
 * @date 2022-02-27
 */
@Api("学生家庭成员情况接口")
@RestController
@RequestMapping("/archives/relatives")
public class SysRelativesController extends BaseController
{
    @Autowired
    private ISysRelativesService sysRelativesService;

    /**
     * 查询家庭成员情况列表
     */
    @ApiOperation("查询家庭成员情况列表")
    @PreAuthorize("@ss.hasPermi('archives:relatives:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRelatives sysRelatives)
    {
        startPage();
        List<SysRelatives> list = sysRelativesService.selectSysRelativesList(sysRelatives);
        return getDataTable(list);
    }

    /**
     * 导出家庭成员情况列表
     */
    @ApiOperation("导出家庭成员情况列表")
    @PreAuthorize("@ss.hasPermi('archives:relatives:export')")
    @Log(title = "家庭成员情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRelatives sysRelatives)
    {
        List<SysRelatives> list = sysRelativesService.selectSysRelativesList(sysRelatives);
        ExcelUtil<SysRelatives> util = new ExcelUtil<SysRelatives>(SysRelatives.class);
        util.exportExcel(response, list, "家庭成员情况数据");
    }

    /**
     * 获取家庭成员情况详细信息
     */
    @ApiOperation("获取家庭成员情况详细信息")
    @PreAuthorize("@ss.hasPermi('archives:relatives:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysRelativesService.selectSysRelativesById(id));
    }

    /**
     * 新增家庭成员情况
     */
    @ApiOperation("新增家庭成员情况")
    @PreAuthorize("@ss.hasPermi('archives:relatives:add')")
    @Log(title = "家庭成员情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRelatives sysRelatives)
    {
        return toAjax(sysRelativesService.insertSysRelatives(sysRelatives));
    }

    /**
     * 修改家庭成员情况
     */
    @ApiOperation("修改家庭成员情况")
    @PreAuthorize("@ss.hasPermi('archives:relatives:edit')")
    @Log(title = "家庭成员情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRelatives sysRelatives)
    {
        return toAjax(sysRelativesService.updateSysRelatives(sysRelatives));
    }

    /**
     * 删除家庭成员情况
     */
    @ApiOperation("删除家庭成员情况")
    @PreAuthorize("@ss.hasPermi('archives:relatives:remove')")
    @Log(title = "家庭成员情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysRelativesService.deleteSysRelativesByIds(ids));
    }
}
